package edu.ntu.im.p2ptrade;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.LinkedList;
import java.util.List;

public class RecordManager {
	private static List<Record> records = new LinkedList<Record>();
	public static class  Record{
		String msg;
		String objHex;
		String fromWhom;
		String toWhom;
		String dgHex;
		public String getDgHex() {
			return dgHex;
		}
		public String getFromWhom() {
			return fromWhom;
		}
		public String getMsg() {
			return msg;
		}
		public String getObjHex() {
			return objHex;
		}
		public String getToWhom() {
			return toWhom;
		}
		Record(String msg, String objHex, String from, String toWhom, String dsHex){
			this.msg = msg;
			this.objHex = objHex;
			this.fromWhom = from;
			this.toWhom = toWhom;
			this.dgHex = dsHex;
		}
	}
	
	public  static void addRecord(String msg, Object obj, String from, String toWhom, byte[] dsHex){
		ByteArrayOutputStream  baos = new ByteArrayOutputStream();
		try {
			ObjectOutputStream ois = new ObjectOutputStream(baos);
			ois.writeObject(obj);
			ois.close();
			baos.close();
			String objHex = Util.dumpBytes(baos.toByteArray());
			String dsHexStr = Util.dumpBytes(dsHex);
			Record record= new Record(msg, objHex, from , toWhom, dsHexStr);
			records.add(record);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	public static  List<Record> getRecords(){
		return records;
	}
}
